/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.click.app.model;

/**
 *
 * @author arnold
 */
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 *
 * @author arnold
 */
@Entity
@Table(name = "product_types")
public class ProductType extends BaseObject implements Serializable {

    private Long id;
    private String name;
    private String observation;
    private String nameEs;
    private String observationEs;
    private byte[] imageProductType;
    private List<Product> products;
    private Category category;

    public ProductType() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(length = 255)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(length = 2500)
    public String getObservation() {
        return observation;
    }

    public void setObservation(String observation) {
        this.observation = observation;
    }

    @Column(name = "name_es", length = 255)
    public String getNameEs() {
        return nameEs;
    }

    public void setNameEs(String nameEs) {
        this.nameEs = nameEs;
    }

    @Column(name = "observation_es", length = 2500)
    public String getObservationEs() {
        return observationEs;
    }

    public void setObservationEs(String observationEs) {
        this.observationEs = observationEs;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ProductType other = (ProductType) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if ((this.observation == null) ? (other.observation != null) : !this.observation.equals(other.observation)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 53 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 53 * hash + (this.observation != null ? this.observation.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append("id", this.id).append("name", this.name).append("observation", this.observation);
        return sb.toString();
    }

    //@Lob
    @Column(name = "image_product_type", nullable = true)
    public byte[] getImageProductType() {
        return imageProductType;
    }

    public void setImageProductType(byte[] imageProductType) {
        this.imageProductType = imageProductType;
    }

    /**
     * @return the products
     */
    @OneToMany(fetch = FetchType.LAZY)
    public List<Product> getProducts() {
        if (products == null) {
            products = new ArrayList<Product>();
        }
        return products;
    }

    /**
     * @param products the products to set
     */
    public void setProducts(List<Product> products) {
        this.products = products;
    }

    /**
     * @return the category
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id_category")
    public Category getCategory() {
        return category;
    }

    /**
     * @param category the category to set
     */
    public void setCategory(Category category) {
        this.category = category;
    }

    @Transient
    public String getNameLang() {
        if (getLanguaje() != null && getLanguaje().equals("es") && getNameEs() != null) {
            return getNameEs();
        }
        return getName();
    }
    @Transient
    public String getObservationLang() {
        if (getLanguaje() != null && getLanguaje().equals("es") && getNameEs() != null) {
            return getObservationEs();
        }
        return getName();
    }

}
